package org.assistant.common.web.servlet.mvc;

import javax.servlet.http.HttpServletRequest;

import org.assistant.common.exception.ParseMethodException;

public class MethodNameParserFactory {
	private MethodNameParser methodNameParser;
	private static MethodNameParserFactory instance;

	private MethodNameParserFactory() {
	}

	public static MethodNameParserFactory getInstance() {
		if (instance == null) {
			instance = new MethodNameParserFactory();
		}
		return instance;
	}

	/**
	 * 获取当前请求的方法名，如果找不到当前请求的方法，则返回空字符串
	 * 
	 * @param request
	 * @return
	 */
	public String getMethodName(HttpServletRequest request) {
		if (methodNameParser == null) {
			// methodNameParser = new InternalPathMethodNameParser();
			methodNameParser = new ParameterMethodNameParser();
		}
		try {
			return methodNameParser.getMethodName(request);
		} catch (ParseMethodException e) {
			e.printStackTrace();
			return "";
		}
	}
}
